using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Impact.Model.Objects
{
	/// <summary>
	/// Strongly-typed collection for the PagePlugin class.
	/// </summary>
    [Serializable]
	public partial class PagePluginCollection : ActiveList<PagePlugin, PagePluginCollection>
	{	   
		public PagePluginCollection() {}
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the impact_PagePlugins table.
	/// </summary>
	[Serializable]
	public partial class PagePlugin : ActiveRecord<PagePlugin>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public PagePlugin()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public PagePlugin(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public PagePlugin(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public PagePlugin(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("impact_PagePlugins", TableType.Table, DataService.GetInstance("ImpactProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarRegistrationId = new TableSchema.TableColumn(schema);
				colvarRegistrationId.ColumnName = "RegistrationId";
				colvarRegistrationId.DataType = DbType.Int32;
				colvarRegistrationId.MaxLength = 0;
				colvarRegistrationId.AutoIncrement = true;
				colvarRegistrationId.IsNullable = false;
				colvarRegistrationId.IsPrimaryKey = true;
				colvarRegistrationId.IsForeignKey = false;
				colvarRegistrationId.IsReadOnly = false;
				colvarRegistrationId.DefaultSetting = @"";
				colvarRegistrationId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRegistrationId);
				
				TableSchema.TableColumn colvarPageId = new TableSchema.TableColumn(schema);
				colvarPageId.ColumnName = "PageId";
				colvarPageId.DataType = DbType.Int32;
				colvarPageId.MaxLength = 0;
				colvarPageId.AutoIncrement = false;
				colvarPageId.IsNullable = false;
				colvarPageId.IsPrimaryKey = false;
				colvarPageId.IsForeignKey = true;
				colvarPageId.IsReadOnly = false;
				colvarPageId.DefaultSetting = @"";
				
					colvarPageId.ForeignKeyTableName = "impact_Pages";
				schema.Columns.Add(colvarPageId);
				
				TableSchema.TableColumn colvarPluginId = new TableSchema.TableColumn(schema);
				colvarPluginId.ColumnName = "PluginId";
				colvarPluginId.DataType = DbType.Guid;
				colvarPluginId.MaxLength = 0;
				colvarPluginId.AutoIncrement = false;
				colvarPluginId.IsNullable = false;
				colvarPluginId.IsPrimaryKey = false;
				colvarPluginId.IsForeignKey = false;
				colvarPluginId.IsReadOnly = false;
				colvarPluginId.DefaultSetting = @"";
				colvarPluginId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPluginId);
				
				TableSchema.TableColumn colvarLocation = new TableSchema.TableColumn(schema);
				colvarLocation.ColumnName = "Location";
				colvarLocation.DataType = DbType.Int32;
				colvarLocation.MaxLength = 0;
				colvarLocation.AutoIncrement = false;
				colvarLocation.IsNullable = false;
				colvarLocation.IsPrimaryKey = false;
				colvarLocation.IsForeignKey = false;
				colvarLocation.IsReadOnly = false;
				
						colvarLocation.DefaultSetting = @"((0))";
				colvarLocation.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLocation);
				
				TableSchema.TableColumn colvarParameters = new TableSchema.TableColumn(schema);
				colvarParameters.ColumnName = "Parameters";
				colvarParameters.DataType = DbType.Binary;
				colvarParameters.MaxLength = 4000;
				colvarParameters.AutoIncrement = false;
				colvarParameters.IsNullable = true;
				colvarParameters.IsPrimaryKey = false;
				colvarParameters.IsForeignKey = false;
				colvarParameters.IsReadOnly = false;
				colvarParameters.DefaultSetting = @"";
				colvarParameters.ForeignKeyTableName = "";
				schema.Columns.Add(colvarParameters);
				
				TableSchema.TableColumn colvarSequence = new TableSchema.TableColumn(schema);
				colvarSequence.ColumnName = "Sequence";
				colvarSequence.DataType = DbType.Int32;
				colvarSequence.MaxLength = 0;
				colvarSequence.AutoIncrement = false;
				colvarSequence.IsNullable = false;
				colvarSequence.IsPrimaryKey = false;
				colvarSequence.IsForeignKey = false;
				colvarSequence.IsReadOnly = false;
				
						colvarSequence.DefaultSetting = @"((99999))";
				colvarSequence.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSequence);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["ImpactProvider"].AddSchema("impact_PagePlugins",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("RegistrationId")]
		[Bindable(true)]
		public int RegistrationId 
		{
			get { return GetColumnValue<int>(Columns.RegistrationId); }
			set { SetColumnValue(Columns.RegistrationId, value); }
		}
		  
		[XmlAttribute("PageId")]
		[Bindable(true)]
		public int PageId 
		{
			get { return GetColumnValue<int>(Columns.PageId); }
			set { SetColumnValue(Columns.PageId, value); }
		}
		  
		[XmlAttribute("PluginId")]
		[Bindable(true)]
		public Guid PluginId 
		{
			get { return GetColumnValue<Guid>(Columns.PluginId); }
			set { SetColumnValue(Columns.PluginId, value); }
		}
		  
		[XmlAttribute("Location")]
		[Bindable(true)]
		public int Location 
		{
			get { return GetColumnValue<int>(Columns.Location); }
			set { SetColumnValue(Columns.Location, value); }
		}
		  
		[XmlAttribute("Parameters")]
		[Bindable(true)]
		public byte[] Parameters 
		{
			get { return GetColumnValue<byte[]>(Columns.Parameters); }
			set { SetColumnValue(Columns.Parameters, value); }
		}
		  
		[XmlAttribute("Sequence")]
		[Bindable(true)]
		public int Sequence 
		{
			get { return GetColumnValue<int>(Columns.Sequence); }
			set { SetColumnValue(Columns.Sequence, value); }
		}
		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a ImpactPage ActiveRecord object related to this PagePlugin
		/// 
		/// </summary>
		public Impact.Model.Objects.ImpactPage ImpactPage
		{
			get { return Impact.Model.Objects.ImpactPage.FetchByID(this.PageId); }
			set { SetColumnValue("PageId", value.PageId); }
		}
		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varPageId,Guid varPluginId,int varLocation,byte[] varParameters,int varSequence)
		{
			PagePlugin item = new PagePlugin();
			
			item.PageId = varPageId;
			
			item.PluginId = varPluginId;
			
			item.Location = varLocation;
			
			item.Parameters = varParameters;
			
			item.Sequence = varSequence;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varRegistrationId,int varPageId,Guid varPluginId,int varLocation,byte[] varParameters,int varSequence)
		{
			PagePlugin item = new PagePlugin();
			
				item.RegistrationId = varRegistrationId;
			
				item.PageId = varPageId;
			
				item.PluginId = varPluginId;
			
				item.Location = varLocation;
			
				item.Parameters = varParameters;
			
				item.Sequence = varSequence;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn RegistrationIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn PageIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn PluginIdColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn LocationColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn ParametersColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn SequenceColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string RegistrationId = @"RegistrationId";
			 public static string PageId = @"PageId";
			 public static string PluginId = @"PluginId";
			 public static string Location = @"Location";
			 public static string Parameters = @"Parameters";
			 public static string Sequence = @"Sequence";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
